using System;
using System.Configuration;
using Common.Core.Objects;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.Unity.Configuration;
using Microsoft.Practices.Unity.ObjectBuilder;

namespace Common.Unity.Extensions.Configuration
{
	class StrategyConfigurationElement : TypeResolvingConfigurationElement, IObjectWithKey
	{
		/// <summary>
		/// The actual <see cref="System.Type"/> object for the 
		/// type this element is registering.
		/// </summary>
		public Type Type
		{
			get { return TypeResolver.ResolveType( TypeName ); }
		}

		/// <summary>
		/// Source type to configure in the container.
		/// </summary>
		[ConfigurationProperty( TypeNameName, IsRequired = true)]
		public string TypeName
		{
			get { return (string)this[ TypeNameName ]; }
			set { this[ TypeNameName ] = value; }
		}	const string TypeNameName = "type";

		[ConfigurationProperty( StageName, DefaultValue = UnityBuildStage.Initialization, IsRequired = false, IsKey = false )]
		public UnityBuildStage Stage
		{
			get { return (UnityBuildStage)this[StageName]; }
			set { this[StageName] = value; }
		}	const string StageName = "stage";

		object IObjectWithKey.Key
		{
			get { return string.Format( "{0}:{1}", Stage, TypeName ); }
		}
	}
}